<?php
require_once 'models/client.inc';
require_once 'models/orm.inc';

class TMSClientModel extends TCandyModel {
	protected function afterConstruct(){
		$this->_conf_classname_ = 'TMSClient';
	}
	
	protected function beforeSave(TNOrmObject $object){
		if (is_null($object->Active))
			$object->Active = false;
		/*if ($object->Mobile)
			$object->Mobile = mb_substr(preg_replace('/[^\d]+/', '', $object->Mobile), 0, 10);
		if ($object->Phone)	
			$object->Phone = mb_substr(preg_replace('/[^\d]+/', '', $object->Phone), 0, 10);*/
		if (!$object->Roles)	
			$object->Roles = TMSRole::CLIENT;
		return $object;
	}
	
	protected function postProcessProperties(){
		parent::postProcessProperties();
		$this->propertyMetas['Email']->Required = true;
		$this->propertyMetas['Mobile']->Required = true;
		$this->propertyMetas['Address']->Type = TItemPropertyType::PT_MULTILINE;
		unset($this->propertyMetas['Password']);//->Type = TItemPropertyType::PT_PASSWORD;
		unset($this->propertyMetas['Roles']);
		unset($this->propertyMetas['Rehashed']);
	}
	
}
